<?php
namespace UserModule\php;
error_reporting(E_ALL);
require_once __DIR__ . '/../vendor/autoload.php';

use Thrift\ClassLoader\ThriftClassLoader;

//$GEN_DIR = __DIR__.'/ThriftGen/gen-php';
$GEN_DIR = realpath(dirname(__FILE__)).'/../gen-php';

$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', __DIR__ . '/../../lib/php/lib');
$loader->registerNamespace('UserModule', $GEN_DIR);
$loader->registerDefinition('UserModule', $GEN_DIR);
$loader->register();

use Thrift\Protocol\TBinaryProtocol;
use Thrift\Protocol\TMultiplexedProtocol;
use Thrift\Transport\THttpClient;
use Thrift\Transport\TBufferedTransport;
use Thrift\Exception\TException;
use UserModule\InvalidException;
use UserModule\User;

try {
    $socket = new THttpClient('localhost', 80, '/thrift/userserver.php');
    $transport = new TBufferedTransport($socket);
    $protocol = new TBinaryProtocol($transport);

    $loginProtocol = new TMultiplexedProtocol($protocol, 'loginService');
    $loginService = new \UserModule\LoginServiceClient($loginProtocol);
    $result = $loginService->Register('wangzhongwei','areyouok');
    var_dump($result);
    echo '<br/>';

    // $result = $loginService->login('wangzhongwei','areyouok');
    // var_dump($result);
    // echo '<br/>';

    $userProtocol = new TMultiplexedProtocol($protocol, 'userService');
    $userService = new \UserModule\UserServiceClient($userProtocol);
//    $result = $userService->Detail(1);
   // var_dump($result);
    echo '<br/>';

    //$result->age = $result->age+3;
    //$result = $userService->Update($result);
    //var_dump($result);
    echo '<br/>';

    $params = new \UserModule\InParamsUser();
    $params->page = 1;
    $params->pageSize = 10;
   // $result = $userService->search($params);
   // var_dump($result);
    echo '<br/>';

  //  $result = $userService->getAllStatus();
  //  var_dump($result);
    echo '<br/>';





    $transport->close();

} catch (InvalidException $tx) {
    print 'TException: '.$tx->getCode().' '.$tx->getMessage()."\n";
}